package com.nexus.core.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nexus.core.response.ResponseMessage;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.http.MediaType;

import java.io.IOException;

/**
 * @Date 2025/7/31 17:46
 * @Author luzhengning
 **/
public class ResponseUtils {

    public static void sendResponse(HttpServletResponse response, int code, Object data, String message) throws IOException {
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        response.setStatus(code);

        ResponseMessage unauthorized = new ResponseMessage(code, data, message);
        new ObjectMapper().writeValue(response.getOutputStream(), unauthorized);
    }
}
